/**********************************************************
 * Ports:
 *  VL_IN8(&idata,3,0);
 *  VL_OUT8(&dig,7,0);
***********************************************************/

#include <stdlib.h>
#include <bitset>
#include <iostream>
#include <verilated.h>
#include <verilated_vcd_c.h>
#include "VdigDecoder.h"
#include "VdigDecoder___024root.h"

// #define TRACE
#define MAX_TIME 16
#define PERIOD 4
uint64_t sim_time = 0;

void decode(VdigDecoder*, uint);

int main(int argc, char **argv) {
	VdigDecoder* dut = new VdigDecoder;

#ifdef TRACE
	Verilated::traceEverOn(true);
	VerilatedVcdC *m_trace = new VerilatedVcdC;
	dut->trace(m_trace, 2);
	m_trace->open("waveform.vcd");
#endif

	while(sim_time < MAX_TIME) {
		decode(dut, uint(sim_time));
		
#ifdef TRACE
		m_trace->dump(sim_time);
#endif

		sim_time++;
	}
	dut->final();

#ifdef TRACE
	m_trace->close();
#endif

	delete dut;
}

void decode(VdigDecoder* dut, uint data) {
	dut->idata = data;
	dut->eval();
	std::cout << "#" << sim_time << '\t' << std::bitset<8>(uint(dut->dig)) << std::endl;
}
